package com.oj.controller;

import com.oj.entity.Problem;
import com.oj.service.ProblemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


//请求获取题目列表、题目详情页
@Slf4j
@Api(tags="题目管理")
@Controller
@RequestMapping("/problem")
public class ProblemController {

    @Autowired
    ProblemService problemService;

    //获取题目列表
    @GetMapping
    @ApiOperation("获取题目列表")
    @ResponseBody
    public List<Problem> getProblem(){
        log.info("获取题目列表");
       return  problemService.selectAll();
    }

    //获取单个题目详情
    @ApiOperation("获取单个题目详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "题目id",required = true,dataType = "Integer",paramType = "path")
    })
    @GetMapping("/{id}")
    @ResponseBody
    public Problem getProblemById(@PathVariable("id")Integer id) {
        log.info("获取题目详情 题目id：{}",id);
        return  problemService.selectProblemById(id);
    }

}
